package com.d0318;

import java.util.concurrent.TimeUnit;

public class Resource1 {
    public  void f(){
        System.out.println(Thread.currentThread().getName()+":not f() is Running");
        synchronized (this){
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+"f() is Running");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        }

    }
    public  void g(){
        System.out.println(Thread.currentThread().getName()+":not g() is Running");
        synchronized (this){
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName()+"h() is Running");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }
    public  void h(){
        System.out.println(Thread.currentThread().getName()+":not h() is Running");
        synchronized (this){
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName()+"g() is Running");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }
    public static void main(String[] args) {
        Resource1 resource=new Resource1();
        new Thread(()->resource.f()).start();
        new Thread(()->resource.f()).start();
        resource.h();
    }
}
